package testcase;

import common.*;
import java.util.*;

public class JsonBuilderTest
{
    public static void main(String[] args)
    {
	JsonScaner	js = new JsonScaner();
	JsonParser	jp = new JsonParser();
	Filer		fl = new Filer();

	js.scan(fl.getReader(args[0]));
	
	try
	    {
		for(String item: js)
		    {
			jp.word(js.getState(), item);
		    } 
		System.out.println("No errors");
	    }
	catch(NoSuchElementException nsee)
	    {
		System.out.println("No errors");
	    }
	catch(JsonParserException jpe)
	    {
		System.out.printf("%s:%d\n", fl.fname, fl.NR);
		jpe.printStackTrace();
	    }
	catch(JsonScanerException jse)
	    {
		System.out.printf("%s:%d\n", fl.fname, fl.NR);
		jse.printStackTrace();
	    }

	//основные типы
	//java.util.HashMap
	//java.util.Vector
	//java.lang.String

	HashMap<String, JsonObject>	tmph	   = (HashMap<String, JsonObject>)jp.getResult();
	System.out.println(""+tmph.size());

	for(String key: tmph.keySet())
	    {
		System.out.println(key+":"+tmph.get(key).obj.getClass().getCanonicalName());
		for(String key2: ((HashMap<String, JsonObject>)(tmph.get(key).obj)).keySet())
		    {
			System.out.println("\t"+key2+":");
		    }
	    }
    }
}
